const koa = require('koa')
const app = new koa()
const Router = require('koa-router')
// 使用 prefix: '/user' 前缀
const UserRouter = new Router({prefix: '/user'})
UserRouter.get('/:id', (ctx, next) => {
  ctx.response.body = 'hello world UserRouter' 
  console.log('query', ctx.request.query)
  console.log('method', ctx.request.method)
  console.log('params===', ctx.request.params)
})
// app.use((ctx, next) => {
//   ctx.response.body = 'hello world'
//   console.log('query', ctx.request.query)
//   console.log('method', ctx.request.method)
//   console.log('params===', ctx.request.params)
// })
app.use(UserRouter.routes()).use(UserRouter.allowedMethods())
app.listen(9000, () => {
  console.log('koa server 9000')
})